package 类加载器.类的初始化阶段;

import org.junit.Test;

import java.io.*;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO:
 * TODO:1．当创建一个类的实例时，比如使用new关键字，或者通过反射、克隆、反序列化。
 *
 * TODO:2．当调用类的静态方法时，即当使用了字节码invokestatic指令。
 *

 * <P> Description:
 */

public class ActiveUse1 {
    public static void main(String[] args) throws ClassNotFoundException {
       // Order order = new Order();
        Class<?> aClass = Class.forName("类加载器.类的初始化阶段.Order");
    }
    public static final String TARGET = "order.data";
    @Test
    //序列化
    public void test1(){
        ObjectOutputStream oos = null;
        try {
            oos = new ObjectOutputStream(new FileOutputStream(TARGET));
        oos.writeObject(new Order());

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                oos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    @Test
    //反序列化
    public void test2(){
        ObjectInputStream ois = null;
        try {
            ois = new ObjectInputStream(new FileInputStream(TARGET));
            Order order = (Order)ois.readObject();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                ois.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
class Order implements Serializable {
    static {
        System.out.println("Order.static initializer");
    }
}
